#include "fileOperationsHeader.h"
char* listFile(char vfsFileName[], char destinationFileName[])
{
	if(mh==NULL)
		return ERR_VFS_LISTFILE_06;
	char *tempVFSFileName=(char*)malloc(sizeof(char)*strlen(vfsFileName)+1);
	sprintf(tempVFSFileName,"%s",vfsFileName);
	char *tokens=strtok(tempVFSFileName,".");
	char *prevToken=(char*)malloc(sizeof(char)*strlen(tempVFSFileName));
	sprintf(prevToken,"%s",tempVFSFileName);
	while(tokens!=NULL)
	{
		sprintf(prevToken,"%s",tokens);
		tokens=strtok(NULL,".");
	}
	if(prevToken!=NULL && strcmp(prevToken,"txt")!=0)
		return ERR_VFS_LISTFILE_05;
	FILE *fp=fopen(mh->fileSystemLabel,"r+b");
	int currentFileDescriptors=mh->countOfFileDescriptors;
	int maxFileDescriptors=mh->maxDescriptors;
	int noOfBlocks=maxFileDescriptors/2;
	descriptors *d;
	d=(descriptors*)searchBST(vfsFileName);
	if(d==NULL)
		return ERR_VFS_LISTFILE_01;
	int s=d->size;
	int address=(int)arr[d->blockNumber];
	fseek(fp,address,SEEK_SET);
	FILE *fpOut=fopen(destinationFileName,"w");
	if(fpOut==NULL)
		return ERR_VFS_LISTFILE_02;
	char *str=(char*)malloc(sizeof(char)*s);
	int c = fread(str,s,1,fp);
	if(d->type == 'f')
		fwrite(str,s,1,fpOut);
	fclose(fp);
	fclose(fpOut);
	return "SUCCESS";
}
